﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bluyel.Core
{
    /// <summary>
    /// A named data, phys qty length.
    /// </summary>
    public class DPhyLength : DataNamedBase, IDPhyLength
    {
        ValuePhyLength _dVal;

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        public DPhyLength(string name, ITypePhy type, ValuePhyLength dVal)
            : base(name, type)
        {
            _dVal = dVal;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        public DPhyLength(string name, ITypePhy type, VarOrConst varOrConst, ValuePhyLength dVal)
            : base(name, type, varOrConst)
        {
            _dVal = dVal;
        }

        //---------------------------------------------------------------------
        public ValuePhyLength DVal
        {
            get { return _dVal; }
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// return the prefix of the physical qty length (Metre,...).
        /// </summary>
        public TypePhyLengthPrefix Prefix 
        {
            get { return _dVal.Prefix; } 
        }

        //---------------------------------------------------------------------
        public bool SetDVal(ValuePhyLength dval)
        {
            if (dval == null)
                return false;


            _dVal = dval;
            return true;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// exp: 
        /// a=int:12
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string s = Name + "=";
            if (_dVal == null)
                s += Type.ToString() + "(null)";
            else
                s += _dVal.ToString();
            return s;
        }

    }
}
